package com.dldata.devtools30.service.metadata;

import com.dldata.devtools30.entity.DevtModelMetadataTableEntity;
import com.dldata.devtools30.repository.metadata.DevtModelMetadataTableDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;

@Component
@Transactional
public class DevtModelMetadataTableService {
    @Autowired
    private DevtModelMetadataTableDao metadataTableDao;
    
    public List<DevtModelMetadataTableEntity> getAll(){
        return metadataTableDao.getAll();
    }

    public List<DevtModelMetadataTableEntity> getAll(List<String> modeltype){
        return metadataTableDao.getAll(modeltype);
    }
    public DevtModelMetadataTableEntity findByDbTableCode(String tableCode, List<String> modeltype){
        return metadataTableDao.findByDbTableCode(tableCode,modeltype).get(0);
    }
    public List<DevtModelMetadataTableEntity> getAll(String typeid, List<String> modeltype){
        return metadataTableDao.getAll(typeid,modeltype);
    }
    public List<DevtModelMetadataTableEntity> getAll(String typeid, String txtSearch, List<String> modeltype){
        return metadataTableDao.getAll(typeid,txtSearch,modeltype);
    }
    public List<DevtModelMetadataTableEntity> findById(String id){
        return metadataTableDao.findById(id).
                map(Collections::singletonList).
                orElse(Collections.emptyList());
    }

    public void save(DevtModelMetadataTableEntity metadataTableEntity){
//        metadataTableDao.save(metadataTableEntity.getId(),metadataTableEntity);
        metadataTableDao.save(metadataTableEntity);
    }

    public DevtModelMetadataTableEntity findOne(String id){
        return metadataTableDao.findById(id).orElse(null);
    }

    public void deleteOne(String id){
        metadataTableDao.deleteById(id);
    }
}
